<template>
    <div>
        <div class="container" id="wayListID">
            <el-card class="box-card">
                <el-form :inline="true" class="demo-form-inline">
                    <el-form-item label="人员名称">
                        <el-input v-model.trim="name" placeholder="人员名称"></el-input>
                    </el-form-item>
                    <el-form-item label="工号">
                        <el-input v-model.trim="jobNumber" placeholder="工号"></el-input>
                    </el-form-item>
                    <el-form-item label="园区">
                        <el-select v-model="gardenId" placeholder="园区" @change="currentSel($event)">
                            <el-option label="全部" value=""></el-option>
                            <el-option v-for="(item,index) in areaList"
                                       :label="item.name"
                                       :value="item.id"></el-option>

                        </el-select>
                    </el-form-item>
                    <el-form-item label="区域">
                        <el-select v-model="areaId" placeholder="区域">
                            <el-option label="全部" value=""></el-option>
                            <el-option v-for="item in qvList" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="时间">
                        <el-date-picker
                                value-format="yyyy-MM-dd"
                                v-model="value1"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch"
                                   style="margin-left: 230px;">搜索
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="default" icon="el-icon-home" @click="showshr" style="margin-left: 230px;">
                            授权
                        </el-button>
                    </el-form-item>
                </el-form>
            </el-card>
            <!--<div class="handle-box">-->
            <!--<el-button-->
            <!--type="primary"-->
            <!--icon="el-icon-delete"-->
            <!--class="handle-del mr10"-->
            <!--@click="delAllSelection"-->
            <!--&gt;批量删除</el-button>-->
            <!--<el-select v-model="query.address" placeholder="地址" class="handle-select mr10">-->
            <!--<el-option key="1" label="广东省" value="广东省"></el-option>-->
            <!--<el-option key="2" label="湖南省" value="湖南省"></el-option>-->
            <!--</el-select>-->
            <!--</div>-->
            <el-card class="box-card">
                <el-table
                        v-loading="loading"
                        :data="tableData"
                        border
                        class="table"
                        ref="multipleTable"
                        header-cell-class-name="table-header"
                        @selection-change="handleSelectionChange"
                >
                    <!--<el-table-column-->
                    <!--type="index"-->
                    <!--width="50">-->
                    <!--</el-table-column>-->
                    <el-table-column prop="time" label="时间"></el-table-column>
                    <el-table-column prop="name" label="名称"></el-table-column>

                    <el-table-column prop="jobNumber" label="工号"></el-table-column>
                    <el-table-column prop="garden" label="园区"></el-table-column>
                    <el-table-column prop="area" label="区域"></el-table-column>
                    <!--<el-table-column label="发起时间" >-->
                    <!--<template slot-scope="scope"><div>{{scope.row.taskCreateTime}}</div> </template>-->
                    <!--</el-table-column>-->
                    <!--<el-table-column label="合同创建时间" align="center">-->
                    <!--<template slot-scope="scope"><div>{{scope.row.proCreateTime}}</div> </template>-->
                    <!--</el-table-column>-->

                    <!--<el-table-column label="状态" align="center">-->
                    <!--<template slot-scope="scope">-->
                    <!--<el-tag-->
                    <!--:type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"-->
                    <!--&gt;{{scope.row.state}}</el-tag>-->
                    <!--</template>-->
                    <!--</el-table-column>-->

                    <!--<el-table-column prop="date" label="注册时间"></el-table-column>-->
                    <!--<el-table-column label="操作" width="180" align="center">-->
                    <!--<template slot-scope="scope">-->
                    <!--<el-button-->
                    <!--type="text"-->
                    <!--icon="el-icon-edit"-->
                    <!--@click="handleEdit(scope.$index, scope.row)"-->
                    <!--&gt;详情</el-button>-->
                    <!--&lt;!&ndash;<el-button&ndash;&gt;-->
                    <!--&lt;!&ndash;type="text"&ndash;&gt;-->
                    <!--&lt;!&ndash;icon="el-icon-delete"&ndash;&gt;-->
                    <!--&lt;!&ndash;class="red"&ndash;&gt;-->
                    <!--&lt;!&ndash;@click="handleDelete(scope.$index, scope.row)"&ndash;&gt;-->
                    <!--&lt;!&ndash;&gt;删除</el-button>&ndash;&gt;-->
                    <!--</template>-->
                    <!--</el-table-column>-->
                </el-table>
                <div class="pagination">
                    <el-pagination
                            background
                            layout="total, prev, pager, next"
                            :current-page="query.pageIndex"
                            :page-size="query.pageSize"
                            :total="pageTotal"
                            @current-change="handlePageChange"
                    ></el-pagination>
                </div>
            </el-card>
            <div style="display: none">{{changeGardenId}}</div>
            <div style="display: none">{{timeMead}}</div>
        </div>

        <el-dialog
                title="提示"
                style="color: white"
                :visible.sync="dialogshr"
                width="23%"
        >
            <!--:before-close="handleClose"-->
            <el-form label-width="80px">
                <el-form-item label="授权人">
                    <el-input class="zhuanbaninput" v-model.trim="shrname"></el-input>
                </el-form-item>
                <el-form-item label="授予人">
                    <el-input class="zhuanbaninput" v-model.trim="jobNumber"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                 <el-button @click="dialogshr = false">取 消</el-button>
                 <el-button type="primary" v-if="!shrId" @click="addshr">确 定</el-button>
                 <el-button type="primary" v-if="shrId" @click="editshr">确 定</el-button>
            </span>
        </el-dialog>
        <!--&lt;!&ndash; 编辑弹出框 &ndash;&gt;-->
        <!--<el-dialog title="编辑" :visible.sync="editVisible" width="30%">-->
        <!--<el-form ref="form" :model="form" label-width="70px">-->
        <!--<el-form-item label="用户名">-->
        <!--<el-input v-model="form.name"></el-input>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="地址">-->
        <!--<el-input v-model="form.address"></el-input>-->
        <!--</el-form-item>-->
        <!--</el-form>-->
        <!--<span slot="footer" class="dialog-footer">-->
        <!--<el-button @click="editVisible = false">取 消</el-button>-->
        <!--<el-button type="primary" @click="saveEdit">确 定</el-button>-->
        <!--</span>-->
        <!--</el-dialog>-->
    </div>
</template>

<script>
    export default {
        name: 'basetable',
        data() {
            return {
                qvList: [],
                areaList: [],
                value1: '',
                dialogshr: false,
                name: '',//人员名称
                jobNumber: '',//人员名称
                gardenName: '',
                gardenId: '',
                areaId: '',
                areaName: '',
                startTime: '',
                endTime: '',
                query: {
                    pageIndex: 1,
                    pageSize: 10
                },
                loading: true,
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                pageTotal: 0,
                form: {},
                idx: -1,
                id: -1
            };
        },
        created() {
            // ddbase.getAuthCode().then((res)=>{
            //
            // })
            //A0038335 单单
            //A0037835 大成哥
        },
        mounted() {
            this.getData()
            this.getTree()
        },
        computed: {
            changeGardenId() {
                if (this.gardenId == '') {
                    this.qvList = []
                    this.areaId = ''
                } else {
                    let des = this.areaList.filter((currentValue) => {
                        return currentValue.id == this.gardenId;
                    })
                    console.log(des)
                    this.qvList = des[0].areaList
                }
            },
            timeMead() {
                this.startTime = this.value1[0]
                this.endTime = this.value1[1]
                console.log(this.startTime)
                return ''
            }
        },
        methods: {
            currentSel(e) {
                console.log(e)
            },
            getTree() {
                this.$api.tree({}).then((res) => {
                    console.log(".................")
                    console.log(res)
                    this.areaList = res.data
                })
            },
            showshr() {
                this.dialogshr = true
            },
            // 获取 easy-mock 的模拟数据
            getData() {
                this.loading = true;
                const myData = {
                    name: this.name,
                    jobNumber: this.jobNumber,
                    gardenId: this.gardenId,
                    areaId: this.areaId,
                    startTime: this.startTime,
                    endTime: this.endTime,
                    pageNo: this.query.pageIndex,
                    pageSize: this.query.pageSize
                }
                this.$api.pageHistory(myData).then((res) => {
                    console.log(res)
                    this.tableData = res.data.records
                    this.pageTotal = parseInt(res.data.total)
                    this.loading = false
                }).catch((err) => {
                    console.log(err)
                    this.loading = false
                })
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 删除操作
            handleDelete(index, row) {
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.$message.success('删除成功');
                        this.tableData.splice(index, 1);
                    })
                    .catch(() => {
                    });
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            delAllSelection() {
                const length = this.multipleSelection.length;
                let str = '';
                this.delList = this.delList.concat(this.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + ' ';
                }
                this.$message.error(`删除了${str}`);
                this.multipleSelection = [];
            },
            // 编辑操作
            handleEdit(index, row) {
                this.idx = index;
                this.form = row;
                this.editVisible = true;
            },
            // 保存编辑
            saveEdit() {
                this.editVisible = false;
                this.$message.success(`修改第 ${this.idx + 1} 行成功`);
                this.$set(this.tableData, this.idx, this.form);
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            }
        }
    };
</script>

<style>
    .el-dialog__footer {
        justify-content: center;
        margin: 0 auto;
        display: flex;
    }

    .el-card__body {
        background: #232343;
    }

    .el-table__empty-block {
        background: #232343;
        color: white;
    }

    .el-table__empty-text {
        color: white;
    }

    .zhuanbaninput{
        width: 204px !important;
    }

    #wayListID .el-form-item__label {
        width: 82px;
    }

    #wayListID .el-table td .el-table th.is-leaf {
        background: #232343;
        border: none;
        color: white;
    }

    #wayListID .el-table__row {
        background: #232343;
        border: none;
        color: white;
    }

    #wayListID .el-card__body {
        background: #232343;
        border: none;
        color: white;
    }

    #wayListID .el-form-item__content {
        width: 130px;
    }

    .el-input {
        width: 138px;
    }

    #wayListID .el-form-item__label {
        width: 82px;
    }

    #wayListID .is-leaf {
        background: #232343;
        border-color: #232343;
        border: none;
        color: white;
    }

    .el-card {
        border: none !important;
    }

    .el-table__expanded-cell {
        background: #232343;
    }

    .el-table__header-wrapper {
        background: #232343;
    }

    .el-range-input {
        background: rgb(41, 41, 86);
        color: white;
    }

    .table-header {
        border: none;
    }

    .is-scrolling-none {
        background: #232343;
    }

    .el-table--enable-row-transition .el-table__body td {
        border: none;
    }

    .el-table::before {
        background: #232343;
    }

    .el-table tbody tr:hover > td {
        background-color: #232343 !important
    }

    .el-table th, .el-table tr {
        background-color: #232343;
    }

    .el-table--enable-row-hover {
        border: none;
    }

    .el-table--border::after, .el-table--group::after {
        background-color: #232343;
    }
    .el-dialog__footer{
        background: #232343;
    }
    .el-dialog__body{
        background: #232343;
    }
    .el-dialog__header{
        background: #232343;
    }
    .el-input__inner{
        background: rgb(41,41,86);
        border: none;
    }
    .el-dialog__title{
        color: white;
    }

</style>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }


</style>
